<template>
	<view class="container">
		<view class="header">
			<u-input v-model="params.condition" @change="search" class="input" placeholder="搜索" prefixIcon="search"
				prefixIconStyle="font-size: 22px;color: #909399"></u-input>
			<view class="add-lunpan" @click="toAddBaike">
				<view class="">
					创建新的命盘
				</view>
				<u-icon name="arrow-right" size="40"></u-icon>
			</view>
		</view>
		<view class="line">

		</view>
		<scroll-view scroll-y class="scroll-box">
			<view class="item" v-for="item in list" @click="select(item)">
				<view class="left">
					<image v-if="item.select" src="@/static/green-dot.png" mode="" class="select-img"></image>
					<view v-else class="circle">

					</view>
					<view class="info">
						<view class="name">
							{{item.name}}
						</view>
						<view class="flex">
							<view class="sex">
								{{item.sex==1?'男':'女'}}
							</view>
							<view class="">
								{{item.birthday}}
							</view>
						</view>
						<view class="group">
							分组:{{item.groupName||'未分组'}}
						</view>
					</view>
				</view>
				<view class="right">
					<view class="row" style="margin-bottom: 26rpx;">
						<view class="" :style={color:colors[item.nianZhu[0]]}>
							{{item.nianZhu[0]}}
						</view>
						<view class="" :style={color:colors[item.yueZhu[0]]}>
							{{item.yueZhu[0]}}
						</view>
						<view class="" :style={color:colors[item.riZhu[0]]}>
							{{item.riZhu[0]}}
						</view>
						<view class="" :style={color:colors[item.shiZhu[0]]}>
							{{item.shiZhu[0]}}
						</view>
					</view>
					<view class="row">
						<view class="" :style={color:colors[item.nianZhu[1]]}>
							{{item.nianZhu[1]}}
						</view>
						<view class="" :style={color:colors[item.yueZhu[1]]}>
							{{item.yueZhu[1]}}
						</view>
						<view class="" :style={color:colors[item.riZhu[1]]}>
							{{item.riZhu[1]}}
						</view>
						<view class="" :style={color:colors[item.shiZhu[1]]}>
							{{item.shiZhu[1]}}
						</view>
					</view>
				</view>
			</view>
			<uni-load-more :status="status" />
		</scroll-view>
	</view>
</template>
<script setup lang="ts">
	import { ref, reactive, onMounted } from 'vue'
	import { $http, textColors, usePaginatedList,initBaiduStatistics } from "@/common"
	import {
		onLoad,
		onShow,
		onNavigationBarButtonTap
	} from '@dcloudio/uni-app'
	import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
	onNavigationBarButtonTap((e) => {
		if (selectItem.value.qiPanId) {
			uni.navigateTo({
				url: '/pages/baike/baike-result?qiPanId=' + selectItem.value.qiPanId + '&name=' + selectItem.value.name+'&id='+selectItem.value.id
			})
		} else {
			uni.showToast({
				title: '请选择命盘!',
				icon: 'none'
			})
		}
	})
	const colors = ref(textColors)
	const params = ref(
		{
			condition: ''
		}
	)
	onShow(() => {
		// #ifdef H5
		setTimeout(() => {
			document.title = "幸运指南"
		})
		// #endif
	})
	
	onMounted(() => {
		// #ifdef H5
		setTimeout(() => {
			let a = document.getElementsByClassName("uni-page-head__title")[0]
			a.textContent = "选择目标对象"
		})
		// #endif
	})
	const fetchFunction = (query) => {
		return $http.get('wikiMine', query)
	}

	const {
		list,
		fetchList,
		reachBottom,
		onPullDown,
		status
	} = usePaginatedList(fetchFunction, params.value)
	onShow(() => {
		fetchList(true)
	})
	onReachBottom(() => {
		console.log('触底了')
		reachBottom()
	})
	onPullDownRefresh(() => {
		console.log('下拉刷新了')
		onPullDown()
	})
	const search = (val) => {
		console.log(val, 'val')
		params.value.condition = val
		fetchList(true)
	}
	const toDetail = (item) => {
		uni.navigateTo({
			url: '/pages/qipan/detail?params=' + item.result
		})
	}
	const selectItem = ref({})
	const select = (item) => {
		list.value.forEach(i => {
			i.select = false
		})
		item.select = !item?.select ? true : false
		if (item.select) {
			selectItem.value = item
		} else {
			selectItem.value = {}
		}
	}
	const toAddBaike = () => {
		uni.navigateTo({
			url: "/pages/baike/add-baike"
		})
	}
</script>

<style lang="less" scoped>
	.container {
		height: 100vh;

		.header {
			position: fixed;
			top: 0px;
			/* #ifdef H5 */
			   top: 44px;
			/* #endif */
			width: 100%;
			height: 100px;
			background-color: #fff;
			padding: 20rpx;
			z-index: 99;

			.input {
				height: 60rpx;
			}

			.add-lunpan {
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;

				view {
					font-size: 32rpx;
				}
			}
		}

		.line {
			position: fixed;
			top: 100px;
			/* #ifdef H5 */
			   top: 144px;
			/* #endif */
			width: 100%;
			height: 10px;
			background-color: #F9F9F9;
			z-index: 99;
		}

		.scroll-box {
			margin-top: 110px;
			background-color: #fff;
			padding: 0 20rpx;

			.item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 0;
				border-bottom: 1rpx solid #ccc;

				.left {
					display: flex;
					align-items: center;

					.circle {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						border: 4rpx solid #C0C0C0;
					}

					.select-img {
						width: 40rpx;
						height: 40rpx;

					}

					.info {
						margin-left: 10rpx;

						.name {
							font-size: 40rpx;
						}

						.flex {
							display: flex;
							align-items: center;
							margin: 8rpx 0;
							color: #C0C0C0;

							.sex {
								margin-right: 10rpx;
							}
						}

						.group {
							color: #C0C0C0;
						}
					}
				}

				.right {
					.row {
						display: flex;

						view {
							font-size: 38rpx;
							margin-left: 30rpx;
						}
					}
				}
			}
		}
	}
</style>